package com.jian.android.autojipai.app.helper;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.text.TextUtils;

public class SystemTool {

    public static class SystemToolInstance {
        private static final SystemTool instance = new SystemTool();

        private SystemToolInstance() {
        }
    }

    private SystemTool() {
    }

    public static SystemTool getInstance() {
        return SystemToolInstance.instance;
    }

    public boolean isNetworkAvailable(Context context) {
        if (context == null) {
            return false;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
        if (networkCapabilities != null) {
            return networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
        }
        return false;
    }

    public void jumpBrowser(Context context, String str) {
        if (TextUtils.isEmpty(str)) {
            ToastTool.getInstance().show(context, "网址为空，无法跳转");
            return;
        }
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setData(Uri.parse(str));
        Intent createChooser = Intent.createChooser(intent, "选择");
        if (createChooser.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(createChooser);
            return;
        }
        ToastTool.getInstance().show(context, "跳转浏览器失败");
    }

    public boolean isAppInstalled(Context context, String str) {
        try {
            context.getPackageManager().getPackageInfo(str, 0);
            return true;
        } catch (Exception unused) {
            return false;
        }
    }
}
